Make tests compatible with current numpy/scipy/pandas
authorDebian Science Maintainers <debian-science-maintainers@lists.alioth.debian.org>
Sat, 2 Mar 2019 14:59:35 +0000 (14:59 +0000)
committerRebecca N. Palmer <rebecca_palmer@zoho.com>
Sat, 2 Mar 2019 14:59:35 +0000 (14:59 +0000)
These issues are all within test code, i.e. should not affect users.

https://github.com/statsmodels/statsmodels/commit/bb8fba9d4d9883be2991b43b29bfa3a9c3fb325a
https://github.com/statsmodels/statsmodels/commit/310f91da9f07d9483965d624d76dbb7abebbd67f
https://github.com/statsmodels/statsmodels/pull/4911/commits/18dcceefbfed61b0d11ae5884a9f4cea82c2edb5
https://github.com/statsmodels/statsmodels/commit/f1d5eddd44d61099a9f8f90c40c35716a8346cf7

and one new fix only needed on 32 bit Python 2 (integer data loads as
int64, which gets converted to long producing factor names like
C(agecat)[T.4L], which does not match C(agecat)[T.4])

Author: Kevin "bashtage" Sheppard, Peter "thequackdaddy" Quackenbush, Matthew Brett, Rebecca N. Palmer <rebecca_palmer@zoho.com>
Origin: upstream (mostly)
Forwarded: no

Gbp-Pq: Name test_fixes.patch

statsmodels/discrete/tests/test_constrained.py
statsmodels/formula/tests/test_formula.py
statsmodels/iolib/tests/test_foreign.py
statsmodels/nonparametric/tests/test_kde.py
statsmodels/tsa/statespace/tests/test_mlemodel.py
statsmodels/tsa/statespace/tests/test_representation.py
statsmodels/tsa/statespace/tests/test_tools.py

index 9a159eddf08482d3caf664287e30e756ba25984a..b871b103da5e5ecd923de76fc8713cfda5b749ee 100644 (file)
@@ -49,7 +49,7 @@ agecat        smokes  deaths  pyears
 
 data = pd.read_csv(StringIO(ss), delimiter='\t')
 data['logpyears'] = np.log(data['pyears'])
-
+data['agecat'] = data['agecat'].astype(int) # avoid int vs long test failure on 32 bit Python 2
 
 class CheckPoissonConstrainedMixin(object):
 
index 232bfca0e1cbb83f2c38fa76f2a4a2ef05c1b03a..ef4cf3bee559a32a217a2dfeb78d3fb00f4bef7a 100644 (file)
@@ -8,7 +8,6 @@ from statsmodels.datasets.longley import load, load_pandas
 
 import numpy.testing as npt
 from statsmodels.tools.testing import assert_equal
-from numpy.testing.utils import WarningManager
 
 
 longley_formula = 'TOTEMP ~ GNPDEFL + GNP + UNEMP + ARMED + POP + YEAR'
@@ -34,14 +33,10 @@ class CheckFormulaOLS(object):
 
     def test_summary(self):
         # smoke test
-        warn_ctx = WarningManager()
-        warn_ctx.__enter__()
-        try:
+        with warnings.catch_warnings():
             warnings.filterwarnings("ignore",
                                     "kurtosistest only valid for n>=20")
             self.model.fit().summary()
-        finally:
-            warn_ctx.__exit__()
 
 
 class TestFormulaPandas(CheckFormulaOLS):
index c5c13bf780d8831afbd7a7c30c70772f30e4a8c3..5bb2cdd4c04ea1fa070407d22605cf3665229ec2 100644 (file)
@@ -17,9 +17,6 @@ from statsmodels.iolib.foreign import (StataWriter, genfromdta,
 from statsmodels.datasets import macrodata
 
 
-from statsmodels.compat.pandas import version as pandas_version
-pandas_old = pandas_version < '0.9'
-
 # Test precisions
 DECIMAL_4 = 4
 DECIMAL_3 = 3
@@ -115,7 +112,6 @@ def test_stata_writer_unicode():
     # make sure to test with characters outside the latin-1 encoding
     pass
 
-@dec.skipif(pandas_old)
 def test_genfromdta_datetime():
     results = [(datetime(2006, 11, 19, 23, 13, 20), 1479596223000,
             datetime(2010, 1, 20), datetime(2010, 1, 8), datetime(2010, 1, 1),
@@ -167,7 +163,6 @@ def test_date_converters():
         assert_equal(_datetime_to_stata_elapsed(
                      _stata_elapsed_date_to_datetime(i, "ty"), "ty"), i)
 
-@dec.skipif(pandas_old)
 def test_datetime_roundtrip():
     dta = np.array([(1, datetime(2010, 1, 1), 2),
                     (2, datetime(2010, 2, 1), 3),
index feb664934b159ab85f8da3d9e84dbdf6781bb08b..b72ef26a634cc70afb26791323e920798dc1cac4 100644 (file)
@@ -72,7 +72,7 @@ class CheckKDE(object):
         # added it as test method to TestKDEGauss below
         # inDomain is not vectorized
         #kde_vals = self.res1.evaluate(self.res1.support)
-        kde_vals = [self.res1.evaluate(xi) for xi in self.res1.support]
+        kde_vals = [np.squeeze(self.res1.evaluate(xi)) for xi in self.res1.support]
         kde_vals = np.squeeze(kde_vals)  #kde_vals is a "column_list"
         mask_valid = np.isfinite(kde_vals)
         # TODO: nans at the boundaries
@@ -217,7 +217,7 @@ class CheckKDEWeights(object):
 
     def test_compare(self):
         xx = self.res1.support
-        kde_vals = [self.res1.evaluate(xi) for xi in xx]
+        kde_vals = [np.squeeze(self.res1.evaluate(xi)) for xi in xx]
         kde_vals = np.squeeze(kde_vals)  #kde_vals is a "column_list"
         mask_valid = np.isfinite(kde_vals)
         # TODO: nans at the boundaries
index d36ad8232b7fcd21c0bcc6d50b1557eec0eaf923..cd332c4c19cea0cd7b84fd52d24c530ab3491788 100644 (file)
@@ -660,7 +660,7 @@ def test_pandas_endog():
     mod.filter([])
 
     # Example : pandas.Series, string datatype
-    endog = pd.Series(['a'], index=dates)
+    endog = pd.Series(['a', 'b'], index=dates)
     # raises error due to direct type casting check in Statsmodels base classes
     assert_raises(ValueError, check_endog, endog, **kwargs)
 
index 11734e3282a028b9c171f4a0dca8be900fd53f5f..91e918c5d96ed9883e9cfa7c753238cdcea552b6 100644 (file)
@@ -1033,8 +1033,8 @@ def test_simulate():
                   state_shocks)
 
     # ARMA(1,1): phi = [0.1], theta = [0.5], sigma^2 = 2
-    phi = np.r_[0.1]
-    theta = np.r_[0.5]
+    phi = 0.1
+    theta = 0.5
     mod = sarimax.SARIMAX([0], order=(1,0,1))
     mod.update(np.r_[phi, theta, sigma2])
 
index 941a34a3c9a9dce0e50cb7c34f5c1c0fe5740545..ede5d919305e48de1372ced2359a35e0760111b6 100644 (file)
@@ -357,7 +357,7 @@ class TestConstrainStationaryMultivariate(object):
                 cov = np.eye(unconstrained.shape[0])
             constrained, _ = tools.constrain_stationary_multivariate(unconstrained, cov)
             companion = tools.companion_matrix(
-                [1] + [-constrained[i] for i in range(len(constrained))]
+                [1] + [-np.squeeze(constrained[i]) for i in range(len(constrained))]
             ).T
             assert_equal(np.max(np.abs(np.linalg.eigvals(companion))) < 1, True)